<?php

namespace App\Http\Controllers\Api;

use App\Atransform\ArticleTransform;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Modules\Shop\Entities\Article;

class ArticleController extends XcxController
{
//    开发获得所有文章接口
    public function article(Article $article)
    {
//        这里调整一下，试试带参数的情况下怎么传递数据
//        $res = \request()->query();
//        sleep(5);证明确实可以异步获得到文章数据

        $cid = \request()->query('category_id',0);
        if ($cid){
            $article = Article::where('category_id',$cid)->get();
        }else{
            $article = Article::get();
        }
        return $this->response->collection($article,new ArticleTransform());
    }

//    开发获得推荐文章
    public function hotarticle()
    {
        return $this->response->collection(Article::where('iscommend',1)->get(),new ArticleTransform());
    }

//    找到单一一条文章数据
    public function oneArticle($id){
        return $this->response->item(Article::find($id),new ArticleTransform());
    }

}
